package org.bee.service;

import jakarta.annotation.Resource;
import org.bee.input.PermissionSearchVo;
import org.bee.mappers.PermissionMapper;
import org.bee.model.Permission;
import org.bee.model.PermissionExample;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionService {
    @Resource
    private PermissionMapper permissionMapper;

    /**
     * 插入权限
     * @param permission 权限实体
     * @return 插入结果
     */
    public int insert(Permission permission) {
        return permissionMapper.insert(permission);
    }

    /**
     * 删除权限
     * @param permissionId 权限id
     * @return 删除结果
     */
    public int delete(String permissionId) {
        return permissionMapper.deleteByPrimaryKey(permissionId);
    }

    /**
     * 根据主键更新权限
     * @param permission 权限实体
     * @return 更新结果
     */
    public int update(Permission permission) {
        return permissionMapper.updateByPrimaryKeySelective(permission);
    }

    /**
     * 查询接口权限表
     * @param permissionSearchVo 接口权限表查询参数
     * @return 接口权限表列表
     */
    public List<Permission> select(PermissionSearchVo permissionSearchVo) {
        PermissionExample permissionExample = new PermissionExample();
        PermissionExample.Criteria criteria = permissionExample.createCriteria();
        if (permissionSearchVo.getLabel() != null) {
            criteria.andLabelLike("%"+permissionSearchVo.getLabel()+"%");
        }
        return permissionMapper.selectByExample(permissionExample);
    }

    /**
     * 根据主键查询权限
     * @param id 主键
     * @return 权限信息
     */
    public Permission selectById(String id) {
        return permissionMapper.selectByPrimaryKey(id);
    }
}
